﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Primitive.Mvvm.Framework.Interfaces;
using UIController.ViewModels;

namespace UIController.Views
{
    public partial class TaskView : UserControl, IWindowContainer
    {
        private TaskViewModel _model;

        public TaskView()
        {
            InitializeComponent();
        }

        public bool Initialize(IModel model, IMediator mediator, List<Exception> exceptions)
        {
            _model = model as TaskViewModel;

            return Refresh(exceptions);
        }

        public void Clear(out Exception exception)
        {
            exception = null;
            _model = null;
        }

        private bool Refresh(List<Exception> exceptions)
        {
            if (_model == null)
                return false;

            var txt = _model.TaskDesc ?? string.Empty;
            linkTask.Text = txt.Length > 25 ? txt.Substring(0, 25) + "..." : txt;
            chkDone.Checked = _model.TaskIsCompleted;
            
            return true;
        }

        private void OnCheckedChanged(object sender, EventArgs e)
        {
            _model.TaskIsCompleted = chkDone.Checked;
        }

        private void OnLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if(_model != null)
                _model.SelectedFile = _model.FileData;
        }

        //private void OnLinkClick(object sender, EventArgs e)
        //{
        //    if (OnTaskClick != null)
        //    {
        //        OnTaskClick(_data);
        //    }
        //}

        //private void linkTask_MouseDown(object sender, MouseEventArgs e)
        //{
        //    DoDragDrop(_data, DragDropEffects.Copy);
        //}

        //private void linkTask_DragOver(object sender, DragEventArgs e)
        //{
        //   e.Effect = DragDropEffects.Move;
        //}
    }
}
